import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["children", "className", "extra", "style", "renderContent"];
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { ConfigProvider } from 'antd-v4';
import classNames from 'classnames';
import omit from 'omit.js';
import { useContext, useEffect, useMemo } from 'react';
import { RouteContext } from '../../index';
import './index.less';

var FooterToolbar = function FooterToolbar(props) {
  var children = props.children,
      className = props.className,
      extra = props.extra,
      style = props.style,
      renderContent = props.renderContent,
      restProps = _objectWithoutProperties(props, _excluded);

  var _useContext = useContext(ConfigProvider.ConfigContext),
      getPrefixCls = _useContext.getPrefixCls;

  var prefixCls = props.prefixCls || getPrefixCls('pro');
  var baseClassName = "".concat(prefixCls, "-footer-bar");
  var value = useContext(RouteContext);
  var width = useMemo(function () {
    var hasSiderMenu = value.hasSiderMenu,
        isMobile = value.isMobile,
        siderWidth = value.siderWidth;

    if (!hasSiderMenu) {
      return undefined;
    } // 0 or undefined


    if (!siderWidth) {
      return '100%';
    }

    return isMobile ? '100%' : "calc(100% - ".concat(siderWidth, "px)"); // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [value.collapsed, value.hasSiderMenu, value.isMobile, value.siderWidth]);

  var dom = _jsxs(_Fragment, {
    children: [_jsx("div", {
      className: "".concat(baseClassName, "-left"),
      children: extra
    }), _jsx("div", {
      className: "".concat(baseClassName, "-right"),
      children: children
    })]
  });
  /** 告诉 props 是否存在 footerBar */


  useEffect(function () {
    if (!value || !(value === null || value === void 0 ? void 0 : value.setHasFooterToolbar)) {
      return function () {};
    }

    value === null || value === void 0 ? void 0 : value.setHasFooterToolbar(true);
    return function () {
      var _value$setHasFooterTo;

      value === null || value === void 0 ? void 0 : (_value$setHasFooterTo = value.setHasFooterToolbar) === null || _value$setHasFooterTo === void 0 ? void 0 : _value$setHasFooterTo.call(value, false);
    }; // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  return _jsx("div", _objectSpread(_objectSpread({
    className: classNames(className, "".concat(baseClassName)),
    style: _objectSpread({
      width: width
    }, style)
  }, omit(restProps, ['prefixCls'])), {}, {
    children: renderContent ? renderContent(_objectSpread(_objectSpread(_objectSpread({}, props), value), {}, {
      leftWidth: width
    }), dom) : dom
  }));
};

export default FooterToolbar;